define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'grant_log/index' + location.search,
                    import_url: 'grant_log/import',
                    table: 'grant_log',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'admin.nickname', title: __('Admin_id')},
                        {field: 'user.nickname', title: __('User_id')},
                        {field: 'activity.name', title: __('Activity_id')},
                        {field: 'coupon.name', title: __('Coupon.name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'coupon.batch_no', title: __('Coupon.batch_no'), operate: 'LIKE'},
                        {field: 'coupon.pay_money', title: __('Coupon.pay_money'), operate:'BETWEEN'},
                        {field: 'coupon.discounts_money', title: __('Coupon.discounts_money'), operate:'BETWEEN'},
                        {field: 'coupon.end_data', title: __('Coupon.end_data'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'status', title: __('Status'),formatter: function (value) {
                                switch (value) {
                                    case 1:return '领取中';
                                    case 2:return '已领取';
                                    case 3:return '领取失败';
                                    case 4:return '已消费';
                                }
                            },searchList:{1:'领取中',2:'已领取',3:'领取失败',4:'已消费'}},
                        {field: 'remark', title: __('Remark'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        //{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
